﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Data;
using CUREEntity;
using System.Web.Security;
using DBUtility;
using System.Web;
using System.Collections;
using CUREDataAccessLayers.Common;
/*************************************************************************************

     liudan  add   不良胶台账
  
*************************************************************************************/
namespace CUREDataAccessLayers.Harmful
{
    public class LedgerDal
    {

        private common comm = new common();

        /// <summary>
        /// 获取不良台账列表
        /// </summary>
        /// <param name="where"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecordCount"></param>
        /// <param name="totalPageCount"></param>
        /// <returns></returns>
        public DataSet GetLedgerList(IDictionary<string, object> where, int pageIndex, int pageSize, out int totalRecordCount, out int totalPageCount)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            totalRecordCount = 0;
            totalPageCount = 0;
            string fid = string.Empty;

            if (where.ContainsKey("fid") && where["fid"] != null && where["fid"].ToString() != "")
            {
                fid = where["fid"].ToString();
            }

            commandText.Append(" select ID,FID,DeviceNo,Spec,ProMonth,ProDay,OrderBatch,TrayNo,TrayBatch, ");
            commandText.Append(" ExpireMonth,ExpireDay,ProTime,Weight,Reason,FClass,");
            commandText.Append(" Machine,Material,FilmModel,OilModel,ActualNum,BTNo,BJBTNO,OkMan,Field, ");
            commandText.Append(" MakeMan,Skiller,to_char(HandlerTime,'yyyy-mm-dd HH24:mi:ss')HandlerTime, ");
            commandText.Append(" FClass2,Machine2,SubModel,SubBTNum,Interfuse,Residual,Remarks,State,Updater ");
            commandText.Append(" from Harmful_Ledger  where 1=1 and State=" + where["state"].ToString() + " ");

            if (fid != null && fid != "")
            {
                commandText.Append(" and FID like '%" + fid.Trim() + "%'");
            }

            try
            {
                ds = PageHelper.GetPagedData(pageIndex, pageSize, commandText.ToString(), "  ID asc ", out totalRecordCount, out totalPageCount);
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return ds;
        }

        /// <summary>
        /// 根据id获取不良橡胶记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataTable GetLedgerById(string id)
        {
            DataTable dt = new DataTable();
            StringBuilder commandText = new StringBuilder();

            commandText.Append(" select ID,FID,DeviceNo,Spec,ProMonth,ProDay,OrderBatch,TrayNo,TrayBatch, ");
            commandText.Append(" ExpireMonth,ExpireDay,ProTime,Weight,Reason,FClass,");
            commandText.Append(" Machine,Material,FilmModel,OilModel,ActualNum,BTNo,BJBTNO,OkMan,Field, ");
            commandText.Append(" MakeMan,Skiller,to_char(HandlerTime,'yyyy-mm-dd HH24:mi:ss')HandlerTime, ");
            commandText.Append(" FClass2,Machine2,SubModel,SubBTNum,Interfuse,Residual,Remarks,State,Updater ");
            commandText.Append(" from Harmful_Ledger  where ID='" + id + "'");

            try
            {
                dt = DbHelperOra.QueryTable(commandText.ToString());
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return dt;
        }

        /// <summary>
        /// 更新台账信息
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool UpdateLedgerInfo(Dictionary<string, object> dic)
        {
            StringBuilder commandText = new StringBuilder();
            bool result = false;
            string state = "0";
            switch (dic["page"].ToString())
            {
                case "Ledger":

                    if (comm.SwitchIsOn("IsMakeApproval"))
                    {
                        state = "1";
                    }
                    else
                    {
                        state = "2";
                    }
                    break;
                case "LedgerApproval": state = "1"; break;
                case "SkillJudgeList": state = "2"; break;
                default: state = "1"; break;
            }
            commandText.Append("update Harmful_Ledger set Weight='" + dic["Weight"].ToString() + "',Reason='" + dic["Reason"].ToString() + "',FClass='" + dic["FClass"].ToString() + "' ");
            commandText.Append(",Machine='" + dic["Machine"].ToString() + "',Material='" + dic["Material"].ToString() + "',FilmModel='" + dic["FilmModel"].ToString() + "' ");
            commandText.Append(",OilModel='" + dic["OilModel"].ToString() + "',ActualNum='" + dic["ActualNum"].ToString() + "',BTNo='" + dic["BTNo"].ToString() + "' ");
            commandText.Append(",BJBTNO='" + dic["BJBTNO"].ToString() + "',OkMan='" + dic["OkMan"].ToString() + "',Field='" + dic["Field"].ToString() + "' ");
            commandText.Append(",MakeMan='" + dic["MakeMan"].ToString() + "',Skiller='" + dic["Skiller"].ToString() + "',HandlerTime=to_date('" + dic["HandlerTime"].ToString() + "','YYYY-MM-DD HH24:MI:SS') ");
            commandText.Append(",FClass2='" + dic["FClass2"].ToString() + "',Machine2='" + dic["Machine2"].ToString() + "',SubModel='" + dic["SubModel"].ToString() + "',SubBTNum='" + dic["SubBTNum"].ToString() + "' ");
            commandText.Append(",Interfuse='" + dic["Interfuse"].ToString() + "',Residual='" + dic["Residual"].ToString() + "',Remarks='" + dic["Remarks"].ToString() + "' ");
            commandText.Append(",State=" + state + ",Updater='" + HttpContext.Current.Request.Cookies["MWS_User"]["name"] + "' ");
            commandText.Append("where ID='" + dic["mid"].ToString() + "'");

            try
            {
                int res = DbHelperOra.ExecuteSql(commandText.ToString());
                if (res > 0)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 添加台账信息
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool AddLedgerInfo(Dictionary<string, object> dic)
        {
            StringBuilder commandText = new StringBuilder();
            bool result = false;
            commandText.Append("insert into Harmful_Ledger values");
            commandText.Append("(" + DbHelperOra.GetMaxID("ID", "Harmful_Ledger") + ",'" + dic["FID"].ToString() + "','" + dic["DeviceNo"].ToString() + "','" + dic["Spec"].ToString() + "',nvl('" + dic["ProMonth"].ToString() + "',0),nvl('" + dic["ProDay"].ToString() + "',0),'" + dic["OrderBatch"].ToString() + "','" + dic["TrayNo"] + "'");
            commandText.Append(",'" + dic["TrayBatch"].ToString() + "','" + dic["ExpireMonth"].ToString() + "','" + dic["ExpireDay"].ToString() + "','" + dic["ProTime"].ToString() + "',nvl('" + dic["Weight"].ToString() + "',0)");
            commandText.Append(",'" + dic["Reason"].ToString() + "','" + dic["FClass"].ToString() + "','" + dic["Machine"].ToString() + "','" + dic["Material"].ToString() + "'");
            commandText.Append(",'" + dic["FilmModel"].ToString() + "','" + dic["OilModel"].ToString() + "','" + dic["ActualNum"].ToString() + "',nvl('" + dic["BTNo"].ToString() + "',0)");
            commandText.Append(",nvl('" + dic["BJBTNO"].ToString() + "',0),nvl('" + dic["OkMan"].ToString() + "',0),'" + dic["Field"].ToString() + "','" + dic["MakeMan"].ToString() + "','" + dic["Skiller"].ToString() + "',to_date('" + dic["HandlerTime"].ToString() + "','YYYY-MM-DD HH24:MI:SS')");
            commandText.Append(",'" + dic["FClass2"].ToString() + "','" + dic["Machine2"].ToString() + "','" + dic["SubModel"].ToString() + "',nvl('" + dic["SubBTNum"].ToString() + "',0),nvl('" + dic["Interfuse"].ToString() + "',0)");
            commandText.Append(",'" + dic["Residual"].ToString() + "','" + dic["Remarks"].ToString() + "',0,'" + HttpContext.Current.Request.Cookies["MWS_User"]["name"] + "')");

            try
            {
                int res = DbHelperOra.ExecuteSql(commandText.ToString());
                if (res > 0)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 更新台账状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public bool ChangeLedgerState(string id, int state)
        {
            StringBuilder commandText = new StringBuilder();
            bool result = false;
            commandText.Append("update Harmful_Ledger set State=" + state + " where ID=" + id + "");
            try
            {
                int res = DbHelperOra.ExecuteSql(commandText.ToString());
                if (res > 0)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 审核事务
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool ApprovalRoutine(Dictionary<string, object> dic)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            StringBuilder commandTextApproval = new StringBuilder();
            commandText.Append("update Harmful_Ledger set State=" + dic["state"].ToString() + " where ID=" + dic["id"].ToString() + " ");
            commandTextApproval.Append("insert into Approval values(" + DbHelperOra.GetMaxID("ID", "Approval") + ",'" + dic["reason"].ToString() + "'," + dic["value"].ToString() + "," + dic["approval"].ToString() + ",to_date('" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "','yyyy/MM/dd HH24:mi:ss'),'" + HttpContext.Current.Request.Cookies["MWS_User"]["name"] + "','" + dic["fid"].ToString() + "'," + dic["id"].ToString() + ")");
            ArrayList list = new ArrayList();
            list.Add(commandText);
            list.Add(commandTextApproval);
            try
            {

                DbHelperOra.ExecuteSqlTran(list);
                result = true;
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }


        /// <summary>
        /// 实验申请事务
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool ExpApplyRoutine(Dictionary<string, object> dic)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            StringBuilder commandTextExp = new StringBuilder();

            commandText.Append("update Harmful_Ledger set State=" + dic["state"].ToString() + " where ID=" + dic["id"].ToString() + " ");

            if (dic["page"].ToString() == "ExpList")
            {
                commandTextExp.Append("update Expapply set STATE=1,SULFURSPEC='" + dic["SULFURSPEC"].ToString() + "',SULFULACTUAL='" + dic["SULFULACTUAL"].ToString() + "',SULFULJUDGE='" + dic["SULFULJUDGE"].ToString() + "'");
                commandTextExp.Append(",WEIGHTSPEC='" + dic["WEIGHTSPEC"].ToString() + "',WEIGHTACTUAL='" + dic["WEIGHTACTUAL"].ToString() + "',WEIGHTJUDGE='" + dic["WEIGHTJUDGE"].ToString() + "'");
                commandTextExp.Append(",RPAGSPEC='" + dic["RPAGSPEC"].ToString() + "',RPAGACTUAL='" + dic["RPAGACTUAL"].ToString() + "',RPAJUDGE='" + dic["RPAJUDGE"].ToString() + "'");
                commandTextExp.Append(",RPATSSPEC='" + dic["RPATSSPEC"].ToString() + "',RPATSACTUAL='" + dic["RPATSACTUAL"].ToString() + "',RPATSJUDGE='" + dic["RPATSJUDGE"].ToString() + "'");
                commandTextExp.Append(",BPSPEC='" + dic["BPSPEC"].ToString() + "',BPACTUAL='" + dic["BPACTUAL"].ToString() + "',BPJUDGE='" + dic["BPJUDGE"].ToString() + "'");
                commandTextExp.Append(",RESULTREMARKS='" + dic["RESULTREMARKS"].ToString() + "',APPROVALREASON='' where ID=" + dic["id"].ToString() + "");
            }
            else
            {


                commandTextExp.Append("insert into Expapply values(" + DbHelperOra.GetMaxID("ID", "Expapply") + "," + dic["id"].ToString() + ",'" + dic["fid"].ToString() + "','" + dic["reason"].ToString() + "',to_date('" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "','yyyy/MM/dd HH24:mi:ss'),'" + HttpContext.Current.Request.Cookies["MWS_User"]["name"] + "',");
                commandTextExp.Append("'" + dic["judgename"].ToString() + "','" + dic["typeno"].ToString() + "','" + dic["mcno"].ToString() + "',");
                commandTextExp.Append("" + dic["startbt"].ToString() + "," + dic["endbt"].ToString() + "," + dic["num"].ToString() + ",");
                commandTextExp.Append("to_date('" + dic["fdate"].ToString() + "','yyyy/MM/dd'),'" + dic["desc"].ToString() + "','" + dic["rubberput"].ToString() + "',");
                commandTextExp.Append("'" + dic["cont"].ToString() + "','" + dic["cate"].ToString() + "','" + dic["deviceabnormal"].ToString() + "','" + dic["devicecontent"].ToString() + "',");
                commandTextExp.Append("'" + dic["skillabnormal"].ToString() + "','" + dic["skillcontent"].ToString() + "','" + dic["lotabnormal"].ToString() + "','" + dic["lotcontent"].ToString() + "',");
                commandTextExp.Append("'" + dic["workabnormal"].ToString() + "','" + dic["workcontent"].ToString() + "','" + dic["rubberno"].ToString() + "','" + dic["rubberlot"].ToString() + "',");
                commandTextExp.Append("" + dic["rubbernum"].ToString() + "," + dic["rubberreal"].ToString() + ",'" + dic["eleno"].ToString() + "','" + dic["elelot"].ToString() + "',");
                commandTextExp.Append("" + dic["elenum"].ToString() + "," + dic["elereal"].ToString() + ",'" + dic["tireno"].ToString() + "','" + dic["tirelot"].ToString() + "',");
                commandTextExp.Append("" + dic["tirenum"].ToString() + "," + dic["tirereal"].ToString() + ",'" + dic["prono"].ToString() + "','" + dic["prolot"].ToString() + "',");
                commandTextExp.Append("" + dic["pronum"].ToString() + "," + dic["proreal"].ToString() + ",'" + dic["remark"].ToString() + "',");
                commandTextExp.Append("0,'','','','','','','','','','','','','','','','','')");
            }
            ArrayList list = new ArrayList();
            list.Add(commandText);
            list.Add(commandTextExp);
            try
            {

                DbHelperOra.ExecuteSqlTran(list);
                result = true;
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 获取实验列表
        /// </summary>
        /// <param name="where"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecordCount"></param>
        /// <param name="totalPageCount"></param>
        /// <returns></returns>
        public DataSet GetExpList(IDictionary<string, object> where, int pageIndex, int pageSize, out int totalRecordCount, out int totalPageCount)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            totalRecordCount = 0;
            totalPageCount = 0;
            string fid = string.Empty;

            if (where.ContainsKey("fid") && where["fid"] != null && where["fid"].ToString() != "")
            {
                fid = where["fid"].ToString();
            }

            commandText.Append(" select E.ID,E.LEDGERID,E.FID,E.REASON,E.APPLYTIME,E.UPDATER,E.JUDGENAME,E.EXPTYPE, ");
            commandText.Append(" E.MCNO,E.BTNOSTART,E.BTNOEND,E.NUM,E.FDATE,E.DESCRIPTION,E.STATE,");
            commandText.Append(" E.PLACE,E.CONTENT,E.LEDGERCATE ");
            //commandText.Append(" MakeMan,Skiller,to_char(HandlerTime,'yyyy-mm-dd HH24:mi:ss')HandlerTime, ");
            //commandText.Append(" FClass2,Machine2,SubModel,SubBTNum,Interfuse,Residual,Remarks,State,Updater ");
            commandText.Append(" from Expapply E left join Harmful_Ledger H on E.LEDGERID=H.ID   where 1=1 and (E.State=" + where["state"].ToString() + " or E.STATE=-1 )");
            if (!string.IsNullOrEmpty(where["HSTATE"].ToString()))
            {
                commandText.Append(" and H.STATE=" + where["HSTATE"].ToString() + "");
            }

            if (fid != null && fid != "")
            {
                commandText.Append(" and FID like '%" + fid.Trim() + "%'");
            }

            try
            {
                ds = PageHelper.GetPagedData(pageIndex, pageSize, commandText.ToString(), "  ID asc ", out totalRecordCount, out totalPageCount);
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return ds;
        }

        public DataSet GetExpListF(IDictionary<string, object> where, int pageIndex, int pageSize, out int totalRecordCount, out int totalPageCount)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            totalRecordCount = 0;
            totalPageCount = 0;
            string fid = string.Empty;

            if (where.ContainsKey("fid") && where["fid"] != null && where["fid"].ToString() != "")
            {
                fid = where["fid"].ToString();
            }

            commandText.Append(" select E.ID,E.LEDGERID,E.FID,E.REASON,E.APPLYTIME,E.UPDATER,E.JUDGENAME,E.EXPTYPE, ");
            commandText.Append(" E.MCNO,E.BTNOSTART,E.BTNOEND,E.NUM,E.FDATE,E.DESCRIPTION,E.STATE,");
            commandText.Append(" E.PLACE,E.CONTENT,E.LEDGERCATE ");
            //commandText.Append(" MakeMan,Skiller,to_char(HandlerTime,'yyyy-mm-dd HH24:mi:ss')HandlerTime, ");
            //commandText.Append(" FClass2,Machine2,SubModel,SubBTNum,Interfuse,Residual,Remarks,State,Updater ");
            commandText.Append(" from Expapply E left join Harmful_Ledger H on E.LEDGERID=H.ID   where 1=1 and E.State=" + where["state"].ToString());
            if (!string.IsNullOrEmpty(where["HSTATE"].ToString()))
            {
                commandText.Append(" and H.STATE=" + where["HSTATE"].ToString() + "");
            }

            if (fid != null && fid != "")
            {
                commandText.Append(" and FID like '%" + fid.Trim() + "%'");
            }

            try
            {
                ds = PageHelper.GetPagedData(pageIndex, pageSize, commandText.ToString(), "  ID asc ", out totalRecordCount, out totalPageCount);
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return ds;
        }

        /// <summary>
        /// 根据id获取实验申请信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public DataTable GetExpInfo(IDictionary<string, object> where)
        {
            DataTable dt = new DataTable();
            StringBuilder commandText = new StringBuilder();
            commandText.Append("select * from Expapply where ID='" + where["mid"].ToString() + "'");
            try
            {
                dt = DbHelperOra.QueryTable(commandText.ToString());
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return dt;
        }

        /// <summary>
        /// 根据ledgerid获取实验申请信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public DataTable GetExpInfoByLedgerid(IDictionary<string, object> where)
        {
            DataTable dt = new DataTable();
            StringBuilder commandText = new StringBuilder();
            commandText.Append("select * from Expapply where LEDGERID='" + where["mid"].ToString() + "'");
            try
            {
                dt = DbHelperOra.QueryTable(commandText.ToString());
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return dt;
        }

        /// <summary>
        /// QA对实验结果进行审核
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public bool QAApproval(IDictionary<string, object> where)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            StringBuilder commandTextLedger = new StringBuilder();
            commandText.Append("update Expapply set approvalreason='" + where["reason"].ToString() + "',state=" + where["state"].ToString() + " where ID=" + where["id"].ToString() + "");

            try
            {
                if (where["state"].ToString() == "2")
                {
                    string state = "";
                    if (comm.SwitchIsOn("IsSkillApproval"))
                    {
                        state = "5";//需要技术领导审核
                    }
                    else
                    {
                        state = "6";//不需要技术领导审核
                    }
                    commandTextLedger.Append("update Harmful_Ledger set STATE="+state+" where ID=" + where["ledgerid"].ToString() + "");
                    ArrayList list = new ArrayList();
                    list.Add(commandText);
                    list.Add(commandTextLedger);
                    DbHelperOra.ExecuteSqlTran(list);
                    result = true;
                }
                else
                {
                    int res = DbHelperOra.ExecuteSql(commandText.ToString());
                    if (res > 0)
                    {
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 将上传文件路径存入数据库
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public bool UploadExp(IDictionary<string, object> where)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            string existsql = "select PATH from expupload where path='" + where["path"].ToString() + "'";
            string delesql = "delete from expupload where path='" + where["path"].ToString() + "'";

            if (DbHelperOra.Exists(existsql))
            {
                DbHelperOra.ExecuteSql(delesql);
            }
            commandText.Append("insert into expupload values(" + DbHelperOra.GetMaxID("ID", "expupload") + ",'" + where["lid"].ToString() + "','" + where["expid"].ToString() + "','" + where["path"].ToString() + "',to_date('" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + "','yyyy/MM/dd HH24:mi:ss'),'" + HttpContext.Current.Request.Cookies["MWS_User"]["name"] + "')");

            try
            {
                int res = DbHelperOra.ExecuteSql(commandText.ToString());
                if (res > 0)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 根据流水号获取对应的上传文件
        /// </summary>
        /// <param name="ledgerid"></param>
        /// <returns></returns>
        public DataSet GetUploadExp(string ledgerid)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            commandText.Append("select * from expupload where LEDGERID='" + ledgerid + "'");
            try
            {
                ds = DbHelperOra.Query(commandText.ToString());
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return ds;
        }

        /// <summary>
        /// 删除文件数据库记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteFile(string id)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            string delesql = "delete from expupload where ID='" + id + "'";
            try
            {
                int res = DbHelperOra.ExecuteSql(delesql.ToString());
                if (res > 0)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }


        /// <summary>
        /// 更改F卡信息状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public bool UpdateLedgerState(string id, string state)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            commandText.Append("update Harmful_Ledger set STATE=" + state + " where ID=" + id + "");
            try
            {
                int res = DbHelperOra.ExecuteSql(commandText.ToString());
                if (res > 0)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 更新审核结果(技术领导审核实验完毕信息)
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fid"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        public bool ExpResultSkillApproval(string id, string fid, string reason, string state)
        {
            bool result = false;
            StringBuilder commandText = new StringBuilder();
            StringBuilder commandTextLedger = new StringBuilder();
            string hstate = "";
            commandText.Append("insert into approval values(" + DbHelperOra.GetMaxID("ID", "APPROVAL") + ",'" + reason + "','" + state + "',1,to_date('" + DateTime.Now + "','yyyy/MM/dd HH24:mi:ss'),'" + HttpContext.Current.Request.Cookies["MWS_User"]["name"] + "','" + fid + "'," + id + ")");
            if (state == "0")
            {
                hstate = "5";
            }
            else
            {
                hstate = "-2";
            }
            commandTextLedger.Append("update Harmful_Ledger set STATE=" + hstate + " where ID=" + id + "");
            ArrayList list = new ArrayList();
            list.Add(commandText);
            list.Add(commandTextLedger);

            try
            {
                DbHelperOra.ExecuteSqlTran(list);
                result = true;

            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// 获取所有台账信息列表
        /// </summary>
        /// <param name="where"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecordCount"></param>
        /// <param name="totalPageCount"></param>
        /// <returns></returns>
        public DataSet GetCollectList(IDictionary<string, object> where, int pageIndex, int pageSize, out int totalRecordCount, out int totalPageCount)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            totalRecordCount = 0;
            totalPageCount = 0;
            string fid = string.Empty;
            string state = string.Empty;

            if (where.ContainsKey("fid") && where["fid"] != null && where["fid"].ToString() != "")
            {
                fid = where["fid"].ToString();
            }

            if (where.ContainsKey("state") && where["state"] != null && where["state"].ToString() != "")
            {
                state = where["state"].ToString();
            }

            commandText.Append(" select ID,FID,DeviceNo,Spec,ProMonth,ProDay,OrderBatch,TrayNo,TrayBatch, ");
            commandText.Append(" ExpireMonth,ExpireDay,ProTime,Weight,Reason,FClass,");
            commandText.Append(" Machine,Material,FilmModel,OilModel,ActualNum,BTNo,BJBTNO,OkMan,Field, ");
            commandText.Append(" MakeMan,Skiller,to_char(HandlerTime,'yyyy-mm-dd HH24:mi:ss')HandlerTime, ");
            commandText.Append(" FClass2,Machine2,SubModel,SubBTNum,Interfuse,Residual,Remarks,State,Updater ");
            commandText.Append(" from Harmful_Ledger  where 1=1 ");

            if (fid != null && fid != "")
            {
                commandText.Append(" and FID like '%" + fid.Trim() + "%'");
            }

            if (state != null && state != "")
            {
                commandText.Append(" and STATE = " + state + "");
            }

            try
            {
                ds = PageHelper.GetPagedData(pageIndex, pageSize, commandText.ToString(), "  ID asc ", out totalRecordCount, out totalPageCount);
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return ds;
        }


        /// <summary>
        /// 获取审核信息
        /// </summary>
        /// <param name="ledgerid"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public DataTable GetApprovalInfo(string ledgerid, string type)
        {
            DataTable dt = new DataTable();
            StringBuilder commandText = new StringBuilder();
            commandText.Append("select * from APPROVAL where APPROVALTYPE=" + type + " and LEDGER_ID=" + ledgerid + "");
            try
            {
                dt = DbHelperOra.QueryTable(commandText.ToString());
            }
            catch (Exception ex)
            {
                comm.InsertLog(ex.Message);
            }
            return dt;
        }


    }
}
